package it.das.service;

import it.das.task.ITask;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public enum TaskBeanLookupService {
	INSTANCE;
	
	private static ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"Spring-Beans.xml"});
	
	private TaskBeanLookupService(){

	}
	
	public static ITask getTaskByName(String taskName) throws IllegalArgumentException{
		if(taskName == null){
			throw new IllegalArgumentException("ERR: NO_TASK_NAME");
		}
		ITask task = (ITask)appContext.getBean(taskName);
		if(task == null){
			throw new IllegalArgumentException("ERR: NO_TASK_FOUND");
		}
		return task;
	}
}
